<?php
//开启session
	session_start();
//引入配置文件
	include('../public/config.php');
//接收数据
	//var_dump($_SESSION['total']);
	$Area=$_POST['Area'];
	$AddressName=$_POST['AddressName'];
	$Address=$_POST['Address'];
	$Code=$_POST['Code'];
	$Phone=$_POST['Phone'];
	$Tel=$_POST['Tel'];
	$Addtime=time();
	$Status=4;
	if(empty($_SESSION['user'])){
		echo "<script>alert('您还没有登录，请先登录！');window.location.href='./login.php';</script>";
		exit;
	}
	if($Phone==''){
		$Phone=$Tel;
	}
	//初始化数组$idlist
	$idlist=array();
	//取出id值
	$idlist = array_keys($_SESSION['shop']);
//连接数据库
	$con=@mysql_connect(HOST,USER,PASS) or die('连接数据库失败！');
//选择数据库并设置字符集
	mysql_select_db(DBNAME,$con);
	mysql_set_charset('utf8');
//编写sql语句($userid取得登录用户的id号)（将新添加的收货地址存放到数据库）
	$userid="select id from users where username='{$_SESSION['user']}'";
//执行sql语句
	$idresult = mysql_query($userid);
//解析结果集
	$uid = mysql_fetch_assoc($idresult);
//编写插入的sql语句
	$idinfo = implode('',$uid);
	$addinfo="insert into orders(uid,linkman,address,code,phone,total,status,addtime) values({$idinfo},'{$AddressName}','{$Address}','{$Code}','{$Phone}',{$_SESSION['total']},{$Status},{$Addtime})";	
	
//执行插入语句
	$result = mysql_query($addinfo);
//判断是否执行成功
	if(mysql_insert_id($con)>0){
		echo "<script>alert('添加信息成功');window.location.href='order.php';</script>";
		//清除Session
		unset($_SESSION['shop']);
	}else{
		echo "<script>alert('添加信息失败');window.location.href='order.php';</script>";
	}
//释放结果集并关闭数据库
	mysql_free_result($result);
	mysql_free_result($uid);
	mysql_close($con);